<%--
  Created by IntelliJ IDEA.
  User: acer
  Date: 2018/12/18
  Time: 11:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>审核信息</title>
    <script src="/static/js/jquery-3.3.1.js"></script>
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <script src="/static/layuiadmin/layui/layui.js" type="text/javascript"></script>
</head>
<body>
<%--<style type="text/css">--%>
<%--.layui-form-item {--%>
<%--margin-left: 50px;--%>

<%--}--%>
<%--</style>--%>


<form id="myform" action="/insertCategory" method="post" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" id="cid" name="cid" lay-verify="cid" value="${c.cid}" autocomplete="off"
                   class="layui-input">
            <input type="hidden" id="ctime" name="ctime" lay-verify="ctime" value="${c.ctime}" autocomplete="off"
                   class="layui-input">
            <input type="hidden" id="cname" name="cname" lay-verify="cname" value="${c.cname}" autocomplete="off"
                   class="layui-input">
            <input type="hidden" id="cphone" name="cphone" lay-verify="cphone" value="${c.cphone}" autocomplete="off"
                   class="layui-input">
            <input type="hidden" id="cdocumenttype" name="cdocumenttype" lay-verify="cdocumenttype"
                   value="${c.cdocumenttype}" autocomplete="off" class="layui-input">
            <input type="hidden" id="cidentificationnumber" name="cidentificationnumber"
                   lay-verify="cidentificationnumber" value="${c.cidentificationnumber}" autocomplete="off"
                   class="layui-input">
            <input type="hidden" id="cmoney" name="cmoney" lay-verify="cmoney" value="${c.cmoney}" autocomplete="off"
                   class="layui-input">
            <input type="hidden" id="caddress" name="caddress" lay-verify="caddress" value="${c.caddress}"
                   autocomplete="off" class="layui-input">
            <input type="hidden" id="cclaims" name="cclaims" lay-verify="cclaims" value="${c.cclaims}"
                   autocomplete="off" class="layui-input">
            <input type="hidden" id="cmechanism" name="cmechanism" lay-verify="cmechanism" value="${c.cmechanism}"
                   autocomplete="off" class="layui-input">
            <input type="hidden" id="cfa" name="cfa" lay-verify="cfa" value="${c.cfa}" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">授信机构:</label>
        <div class="layui-input-inline" pane>
            <select name="cgid" id="cgid" lay-filter="cgid" class="layui-input  layui-select">
                <option value="0" selected="selected">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">授信产品:</label>
        <div class="layui-input-inline" pane>
            <select name="pid" id="pid" class="layui-input  layui-select">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态:</label>
        <div class="layui-input-block">
            <input type="radio" name="cstate" id="cstate1" value="1" title="审核通过" checked="">
            <input type="radio" name="cstate" value="2" title="审核拒绝">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //创建一个编辑器
        layedit.build('LAY_demo_editor');


        //监听授信产品下拉框
        form.on('select(cgid)', function (data) {
            var cgid = document.getElementById("cgid").value;
            // alert(cgid);
            $.ajax({
                url: "selectProduct",         //请求路径
                datatype: "json",                     //返回的格式
                data: {cgid: cgid},             //参数
                type: "post",                         //请求方式
                success: function (data) {            //请求成功以后
                    var c = document.getElementById("pid");
                    c.options.length = 0;            //清空下拉框
                    console.log(data)
                    for (var i in data.data) {
                        //创建新的option对象
                        var newop = document.createElement("option");
                        //给新增的对象赋值
                        newop.value = data.data[i].pid;
                        newop.innerHTML = data.data[i].pname;
                        //把option对象添加到下拉列表中
                        c.appendChild(newop);
                    }
                    layui.form.render('select');
                }
            })
        });


        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log($('#pid').val());
            $.ajax({
                url: "updateFirstTrial",    //请求的url地址
                dataType: "json",   //返回格式为json
                contentType: "application/json",
                async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                data: {
                    cid: $('#cid').val(),
                    cgid: $('#cgid').val(),
                    pid: $('#pid').val() == null ? 0 : $('#pid').val(),
                    cstate: $('#cstate1').is(":checked") ? 1 : 2
                },  //参数值
                type: "GET",   //请求方式
                success: function (data) {
                    //请求成功时处理
                    layer.alert(data.msg, function (index) {
                        //关闭窗口
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    })
                }
            });
            return false;
        });
    });
</script>

<script>

    onload = function (ev) {
        /**
         * 获取授信机构
         */
        $.ajax({
            url: "selectCreditGranting",  //请求路径
            datatype: "json",           //返回的格式
            data: {id: "123"},           //参数
            type: "post",               //请求方式
            success: function (data) {  //请求成功以后
                console.log(data);
                var c = document.getElementById("cgid");
                for (var d in data.data) {
                    //创建新的option对象
                    var newop = document.createElement("option");
                    //给新增的对象赋值
                    newop.value = data.data[d].cgid;
                    newop.innerHTML = data.data[d].cgname;
                    //把option对象添加到下拉列表中
                    c.appendChild(newop);
                    <%--if (newop.value==${fo.hoid}) {--%>
                    <%--newop.selected = true;--%>
                    <%--}--%>
                }
                layui.form.render('select');

            }
        })
    }
</script>

</body>
</html>
